home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qwidget.h.z / qwidget.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  13.8 KB  |  506 lines

  1. /****************************************************************************
  2. ** $Id: qwidget.h,v 2.53 1998/07/03 00:09:41 hanord Exp $
  3. **
  4. ** Definition of QWidget class
  5. **
  6. ** Created : 931029
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QWIDGET_H
  25. #define QWIDGET_H
  26.  
  27. #ifndef QT_H
  28. #include "qwindowdefs.h"
  29. #include "qobject.h"
  30. #include "qpaintdevice.h"
  31. #include "qpalette.h"
  32. #include "qcursor.h"
  33. #include "qfont.h"
  34. #include "qfontmetrics.h"
  35. #include "qfontinfo.h"
  36. #endif // QT_H
  37.  
  38.  
  39. class QWidget : public QObject, public QPaintDevice
  40. {                        // base class for UI objects
  41.     Q_OBJECT
  42. public:
  43.     QWidget( QWidget *parent=0, const char *name=0, WFlags f=0 );
  44.    ~QWidget();
  45.  
  46.     WId         winId() const;
  47.  
  48.   // GUI style setting
  49.  
  50.     GUIStyle     style() const;
  51.     virtual void setStyle( GUIStyle );
  52.  
  53.   // Widget types and states
  54.  
  55.     bool     isTopLevel()    const;
  56.     bool     isModal()    const;
  57.     bool     isPopup()    const;
  58.     bool     isDesktop()    const;
  59.  
  60.     bool     isEnabled()    const;
  61.     bool     isEnabledTo(QWidget*) const;
  62.     bool     isEnabledToTLW() const;
  63. public slots:
  64.     virtual void setEnabled( bool );
  65.  
  66.   // Widget coordinates
  67.  
  68. public:
  69.     const QRect &frameGeometry() const;
  70.     const QRect &geometry()    const;
  71.     int         x()        const;
  72.     int         y()        const;
  73.     QPoint     pos()        const;
  74.     QSize     size()        const;
  75.     int         width()    const;
  76.     int         height()    const;
  77.     QRect     rect()        const;
  78.     QRect     childrenRect() const;
  79.  
  80.     QSize     minimumSize()    const;
  81.     QSize     maximumSize()    const;
  82.     void     setMinimumSize( const QSize & );
  83.     void     setMinimumSize( int minw, int minh );
  84.     void     setMaximumSize( const QSize & );
  85.     void     setMaximumSize( int maxw, int maxh );
  86.     void     setMinimumWidth( int minw );
  87.     void     setMinimumHeight( int minh );
  88.     void     setMaximumWidth( int maxw );
  89.     void     setMaximumHeight( int maxh );
  90.  
  91.     QSize     sizeIncrement() const;
  92.     void     setSizeIncrement( const QSize & );
  93.     void     setSizeIncrement( int w, int h );
  94.  
  95.     void     setFixedSize( const QSize & );
  96.     void     setFixedSize( int w, int h );
  97.     void     setFixedWidth( int w );
  98.     void     setFixedHeight( int h );
  99.  
  100.   // Widget coordinate mapping
  101.  
  102.     QPoint     mapToGlobal( const QPoint & )     const;
  103.     QPoint     mapFromGlobal( const QPoint & ) const;
  104.     QPoint     mapToParent( const QPoint & )     const;
  105.     QPoint     mapFromParent( const QPoint & ) const;
  106.  
  107.     QWidget    *topLevelWidget()   const;
  108.  
  109.   // Widget attribute functions
  110.  
  111.     enum BackgroundMode { FixedColor, FixedPixmap, NoBackground,
  112.               PaletteForeground, PaletteBackground, PaletteLight,
  113.               PaletteMidlight, PaletteDark, PaletteMid,
  114.               PaletteText, PaletteBase };
  115.  
  116.     BackgroundMode backgroundMode() const;
  117.     void       setBackgroundMode( BackgroundMode );
  118.  
  119.     const QColor  &backgroundColor() const;
  120.     const QColor  &foregroundColor() const;
  121.     virtual void  setBackgroundColor( const QColor & );
  122.  
  123.     const QPixmap *backgroundPixmap() const;
  124.     virtual void   setBackgroundPixmap( const QPixmap & );
  125.  
  126.     const QColorGroup &colorGroup() const;
  127.     const QPalette    &palette()    const;
  128.     virtual void       setPalette( const QPalette & );
  129.  
  130.     const QFont &font()        const;
  131.     virtual void setFont( const QFont & );
  132.     QFontMetrics fontMetrics()    const;
  133.     QFontInfo     fontInfo()    const;
  134.  
  135.     enum PropagationMode { NoChildren, AllChildren,
  136.                SameFont, SamePalette = SameFont };
  137.  
  138.     PropagationMode fontPropagation() const;
  139.     void     setFontPropagation( PropagationMode );
  140.  
  141.     PropagationMode palettePropagation() const;
  142.     void     setPalettePropagation( PropagationMode );
  143.  
  144.     const QCursor &cursor() const;
  145.     virtual void setCursor( const QCursor & );
  146.  
  147.     const char    *caption()    const;
  148.     const QPixmap *icon()    const;
  149.     const char    *iconText()    const;
  150.     bool     hasMouseTracking() const;
  151.  
  152. public slots:
  153.     void     setCaption( const char * );
  154.     void     setIcon( const QPixmap & );
  155.     void     setIconText( const char * );
  156.     void     setMouseTracking( bool enable );
  157.  
  158.   // Keyboard input focus functions
  159.  
  160. public:
  161.     enum FocusPolicy
  162.     { NoFocus = 0, TabFocus = 0x1, ClickFocus = 0x2, StrongFocus = 0x3 };
  163.  
  164.     bool     isActiveWindow() const;
  165.     void     setActiveWindow();
  166.     bool     isFocusEnabled() const;
  167.     FocusPolicy     focusPolicy() const;
  168.     void     setFocusPolicy( FocusPolicy );
  169.     bool     hasFocus() const;
  170.     void     setFocus();
  171.     void     clearFocus();
  172.     static void  setTabOrder( QWidget *, QWidget * );
  173.     void     setFocusProxy( QWidget * );
  174.     QWidget *     focusProxy() const;
  175.  
  176.   // Grab functions
  177.  
  178.     void     grabMouse();
  179.     void     grabMouse( const QCursor & );
  180.     void     releaseMouse();
  181.     void     grabKeyboard();
  182.     void     releaseKeyboard();
  183.     static QWidget *mouseGrabber();
  184.     static QWidget *keyboardGrabber();
  185.  
  186.   // Update/refresh functions
  187.  
  188.     bool     isUpdatesEnabled() const;
  189. public slots:
  190.     void     setUpdatesEnabled( bool enable );
  191.     void     update();
  192.     void     update( int x, int y, int w, int h);
  193.     void     update( const QRect& );
  194.     void     repaint( bool erase=TRUE );
  195.     void     repaint( int x, int y, int w, int h, bool erase=TRUE );
  196.     void     repaint( const QRect &, bool erase=TRUE );
  197.  
  198.   // Widget management functions
  199.  
  200.     virtual void show();
  201.     virtual void hide();
  202.     void     iconify();
  203.  
  204. public:
  205.     virtual bool close( bool forceKill=FALSE );
  206.     bool     isVisible()    const;
  207.     bool     isVisibleTo(QWidget*) const;
  208.     bool     isVisibleToTLW() const;
  209.  
  210. public slots:
  211.     void     raise();
  212.     void     lower();
  213.     virtual void move( int x, int y );
  214.     void     move( const QPoint & );
  215.     virtual void resize( int w, int h );
  216.     void     resize( const QSize & );
  217.     virtual void setGeometry( int x, int y, int w, int h );
  218.     void     setGeometry( const QRect & );
  219.  
  220. public:
  221.     virtual QSize sizeHint() const;
  222.     virtual void  adjustSize();
  223.  
  224.     void     recreate( QWidget *parent, WFlags, const QPoint &,
  225.                bool showIt=FALSE );
  226.  
  227.     void     erase();
  228.     void     erase( int x, int y, int w, int h );
  229.     void     erase( const QRect & );
  230.     void     scroll( int dx, int dy );
  231.  
  232.     void     drawText( int x, int y, const char * );
  233.     void     drawText( const QPoint &, const char * );
  234.  
  235.   // Misc. functions
  236.  
  237.     QWidget     *focusWidget() const;
  238.  
  239.   // drag and drop
  240.  
  241.     void     setAcceptDrops( bool on );
  242.     bool     acceptDrops() const;
  243.                 
  244. public:
  245.     QWidget    *parentWidget() const;
  246.     bool     testWFlags( WFlags n ) const;
  247.     static QWidget     *find( WId );
  248.     static QWidgetMapper *wmapper();
  249.  
  250.   // Event handlers
  251.  
  252. protected:
  253.     bool     event( QEvent * );
  254.     virtual void mousePressEvent( QMouseEvent * );
  255.     virtual void mouseReleaseEvent( QMouseEvent * );
  256.     virtual void mouseDoubleClickEvent( QMouseEvent * );
  257.     virtual void mouseMoveEvent( QMouseEvent * );
  258.     virtual void keyPressEvent( QKeyEvent * );
  259.     virtual void keyReleaseEvent( QKeyEvent * );
  260.     virtual void focusInEvent( QFocusEvent * );
  261.     virtual void focusOutEvent( QFocusEvent * );
  262.     virtual void enterEvent( QEvent * );
  263.     virtual void leaveEvent( QEvent * );
  264.     virtual void paintEvent( QPaintEvent * );
  265.     virtual void moveEvent( QMoveEvent * );
  266.     virtual void resizeEvent( QResizeEvent * );
  267.     virtual void closeEvent( QCloseEvent * );
  268.  
  269. #if defined(_WS_MAC_)
  270.     virtual bool macEvent( MSG * );        // Macintosh event
  271. #elif defined(_WS_WIN_)
  272.     virtual bool winEvent( MSG * );        // Windows event
  273. #elif defined(_WS_PM_)
  274.     virtual bool pmEvent( QMSG * );        // OS/2 PM event
  275. #elif defined(_WS_X11_)
  276.     virtual bool x11Event( XEvent * );        // X11 event
  277. #endif
  278.  
  279.   // Misc. protected functions
  280.  
  281. protected:
  282.     virtual void styleChange( GUIStyle );
  283.     virtual void enabledChange( bool );
  284.     virtual void backgroundColorChange( const QColor & );
  285.     virtual void backgroundPixmapChange( const QPixmap & );
  286.     virtual void paletteChange( const QPalette & );
  287.     virtual void fontChange( const QFont & );
  288.  
  289. #if 1    /* OBSOLETE */
  290.     bool     acceptFocus()    const;
  291.     void     setAcceptFocus( bool );
  292. #endif
  293.     int         metric( int )    const;
  294.  
  295.     void     create( WId );
  296.     void     create( WId, bool initializeWindow, bool destroyOldWindow );
  297.     void     destroy( bool destroyWindow, bool destroySubWindows );
  298.     WFlags     getWFlags()    const;
  299.     void     setWFlags( WFlags );
  300.     void     clearWFlags( WFlags n );
  301.     void     setFRect( const QRect & );
  302.     void     setCRect( const QRect & );
  303.  
  304.     virtual bool focusNextPrevChild( bool next );
  305.  
  306.     QWExtra    *extraData();
  307.  
  308. #if defined(_WS_PM_)
  309.     int         convertYPos( int );
  310.     void     reposChildren();
  311.     WId         frm_wnd;
  312. #endif
  313.  
  314.     QFocusData  *focusData();
  315.  
  316. private slots:
  317.     void     focusProxyDestroyed();
  318.  
  319. private:
  320.     void     setWinId( WId );
  321.     bool     create();
  322.     bool     destroy();
  323.     void     showWindow();
  324.     void     hideWindow();
  325.     void     createExtra();
  326.     void     createSysExtra();
  327.     void     deleteExtra();
  328.     void     deleteSysExtra();
  329.     void     internalMove( int, int );
  330.     void     internalResize( int, int );
  331.     void     internalSetGeometry( int, int, int, int );
  332.     void     deferMove( const QPoint & );
  333.     void     deferResize( const QSize & );
  334.     void     cancelMove();
  335.     void     cancelResize();
  336.     void     sendDeferredEvents();
  337.     void      reparentFocusWidgets( QWidget *parent );
  338.     QFocusData  *focusData( bool create );
  339.     void     setBackgroundColorFromMode();
  340.     void     setBackgroundColorDirect( const QColor & );
  341.     void     setBackgroundModeDirect( BackgroundMode );
  342.     void     setBackgroundEmpty();
  343.  
  344.     WId         winid;
  345.     WFlags     flags;
  346.     QRect     frect;
  347.     QRect     crect;
  348.     QColor     bg_col;
  349.     QPalette     pal;
  350.     QFont     fnt;
  351.     QCursor     curs;
  352.     QWExtra    *extra;
  353.     QWidget    *focusChild; // ### unused now
  354.     static void     createMapper();
  355.     static void     destroyMapper();
  356.     static QWidgetList   *wList();
  357.     static QWidgetList   *tlwList();
  358.     static QWidgetMapper *mapper;
  359.     friend class QApplication;
  360.     friend class QPainter;
  361.     friend class QFontMetrics;
  362.     friend class QFontInfo;
  363.     friend class QETWidget;
  364.  
  365. private:    // Disabled copy constructor and operator=
  366.     QWidget( const QWidget & );
  367.     QWidget &operator=( const QWidget & );
  368. };
  369.  
  370.  
  371. inline bool QWidget::testWFlags( WFlags f ) const
  372. { return (flags & f) != 0; }
  373.  
  374. inline WId QWidget::winId() const
  375. { return winid; }
  376.  
  377. inline bool QWidget::isTopLevel() const
  378. { return testWFlags(WType_TopLevel); }
  379.  
  380. inline bool QWidget::isModal() const
  381. { return testWFlags(WType_Modal); }
  382.  
  383. inline bool QWidget::isPopup() const
  384. { return testWFlags(WType_Popup); }
  385.  
  386. inline bool QWidget::isDesktop() const
  387. { return testWFlags(WType_Desktop); }
  388.  
  389. inline bool QWidget::isEnabled() const
  390. { return !testWFlags(WState_Disabled); }
  391.  
  392. inline const QRect &QWidget::frameGeometry() const
  393. { return frect; }
  394.  
  395. inline const QRect &QWidget::geometry() const
  396. { return crect; }
  397.  
  398. inline int QWidget::x() const
  399. { return frect.x(); }
  400.  
  401. inline int QWidget::y() const
  402. { return frect.y(); }
  403.  
  404. inline QPoint QWidget::pos() const
  405. { return frect.topLeft(); }
  406.  
  407. inline QSize QWidget::size() const
  408. { return crect.size(); }
  409.  
  410. inline int QWidget::width() const
  411. { return crect.width(); }
  412.  
  413. inline int QWidget::height() const
  414. { return crect.height(); }
  415.  
  416. inline QRect QWidget::rect() const
  417. { return QRect(0,0,crect.width(),crect.height()); }
  418.  
  419. inline void QWidget::setSizeIncrement( const QSize &s )
  420. { setSizeIncrement(s.width(),s.height()); }
  421.  
  422. inline void QWidget::setMinimumSize( const QSize &s )
  423. { setMinimumSize(s.width(),s.height()); }
  424.  
  425. inline void QWidget::setMaximumSize( const QSize &s )
  426. { setMaximumSize(s.width(),s.height()); }
  427.  
  428. inline const QColor &QWidget::backgroundColor() const
  429. { return bg_col; }
  430.  
  431. inline const QPalette &QWidget::palette() const
  432. { return pal; }
  433.  
  434. inline const QFont &QWidget::font() const
  435. { return fnt; }
  436.  
  437. inline QFontMetrics QWidget::fontMetrics() const
  438. { return QFontMetrics(this); }
  439.  
  440. inline QFontInfo QWidget::fontInfo() const
  441. { return QFontInfo(this); }
  442.  
  443. inline bool QWidget::hasMouseTracking() const
  444. { return testWFlags(WState_TrackMouse); }
  445.  
  446. inline bool  QWidget::isFocusEnabled() const
  447. { return testWFlags(WState_TabToFocus|WState_ClickToFocus); }
  448.  
  449. inline QWidget::FocusPolicy QWidget::focusPolicy() const
  450. { return (FocusPolicy)((testWFlags(WState_TabToFocus) ? (int)TabFocus : 0) +
  451.                (testWFlags(WState_ClickToFocus)?(int)ClickFocus:0)); }
  452.  
  453. inline bool QWidget::isUpdatesEnabled() const
  454. { return !testWFlags(WState_BlockUpdates); }
  455.  
  456. inline void QWidget::update( const QRect &r )
  457. { update( r.x(), r.y(), r.width(), r.height() ); }
  458.  
  459. inline void QWidget::repaint( bool erase )
  460. { repaint( 0, 0, crect.width(), crect.height(), erase ); }
  461.  
  462. inline void QWidget::repaint( const QRect &r, bool erase )
  463. { repaint( r.x(), r.y(), r.width(), r.height(), erase ); }
  464.  
  465. inline void QWidget::erase()
  466. { erase( 0, 0, crect.width(), crect.height() ); }
  467.  
  468. inline void QWidget::erase( const QRect &r )
  469. { erase( r.x(), r.y(), r.width(), r.height() ); }
  470.  
  471. inline bool QWidget::isVisible() const
  472. { return testWFlags(WState_Visible); }
  473.  
  474. inline void QWidget::move( const QPoint &p )
  475. { move( p.x(), p.y() ); }
  476.  
  477. inline void QWidget::resize( const QSize &s )
  478. { resize( s.width(), s.height()); }
  479.  
  480. inline void QWidget::setGeometry( const QRect &r )
  481. { setGeometry( r.left(), r.top(), r.width(), r.height() ); }
  482.  
  483. inline void QWidget::drawText( const QPoint &p, const char *s )
  484. { drawText( p.x(), p.y(), s ); }
  485.  
  486. inline QWidget *QWidget::parentWidget() const
  487. { return (QWidget *)QObject::parent(); }
  488.  
  489. inline QWidgetMapper *QWidget::wmapper()
  490. { return mapper; }
  491.  
  492. inline bool QWidget::acceptFocus() const
  493. { return testWFlags(WState_ClickToFocus|WState_TabToFocus); }
  494.  
  495. inline WFlags QWidget::getWFlags() const
  496. { return flags; }
  497.  
  498. inline void QWidget::setWFlags( WFlags f )
  499. { flags |= f; }
  500.  
  501. inline void QWidget::clearWFlags( WFlags f )
  502. { flags &= ~f; }
  503.  
  504.  
  505. #endif // QWIDGET_H
  506.